package com.gulimall.search.controller;

import com.common.exception.BizCodeEnume;
import com.common.to.UpSkuTo;
import com.common.utils.R;
import com.gulimall.search.service.EsProductSaveService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;
@Slf4j
@RequestMapping("es")
@RestController
public class ElasticSaveController {
    @Autowired
    EsProductSaveService esProductSaveService;

    @RequestMapping("/save")
    public R saveEs(@RequestBody List<UpSkuTo> upSkuToList) {
        boolean b=false;
        try {
            b = esProductSaveService.productStatusUp(upSkuToList);
        } catch (IOException e) {
            log.error("ElasticSaveController 商品上架错误"+e);
            return R.error(BizCodeEnume.PRODUCT_EXCEPTION.getCode(),BizCodeEnume.PRODUCT_EXCEPTION.getMsg());
        }
        if(b){
            return R.ok();
        }else{
            return R.error(BizCodeEnume.PRODUCT_EXCEPTION.getCode(),BizCodeEnume.PRODUCT_EXCEPTION.getMsg());
        }

    }
}
